/*
 * File:   Rosenbrock.h
 * Author: jcrada
 *
 * Created on 26 May 2011, 1:01 PM
 */

#ifndef ECB_ROSENBROCK_H
#define	ECB_ROSENBROCK_H

#include "ecb/base/Problem.h"

namespace ecb {

    class Rosenbrock : public Problem {
    public:

        Rosenbrock(const std::string& id = "Rosenbrock", const std::string& name = "Rosenbrock",
                int dimensions = 0, scalar minimum = -2.048, scalar maximum = 2.048,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }

        scalar f(const std::vector<scalar>& x) {
            scalar result = 0.0;
            for (size_t i = 0; i < x.size() - 1; ++i) {
                result += 100 * (x[i] * x[i] - x[i + 1]) * (x[i] * x[i] - x[i + 1]) + (x[i] - 1) * (x[i] - 1);
            }
            return result;
        }
    };
}


#endif	/* ECB_ROSENBROCK_H */

